<!DOCTYPE html>
<html lang="en">
	<head>
		{include file='public/header' /}
        {include file='public/comn_css' /}
	</head>
	<body>
		<!--Preloader-->
		<div class="preloader-it">
			<div class="la-anim-1"></div>
		</div>
		<!--/Preloader-->
		<div class="wrapper  theme-5-active pimary-color-blue">
					
		<!-- Top Menu Items -->
			{include file='public/top_menu' /}
		<!-- /Top Menu Items -->
		
		<!-- Left Sidebar Menu -->
			{include file='public/sidebar' /}
		<!-- /Left Sidebar Menu -->

		<!-- Main Content -->
		<div class="page-wrapper">
			<div class="container-fluid">
				<!-- Title -->
				<div class="row heading-bg">
					<div class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
					  <h5 class="txt-dark">系统设置</h5>
					</div>
					<!-- Breadcrumb -->
					<div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
					  <ol class="breadcrumb">
						<li><a href="{:url('admin/index/index')}">首页</a></li>
						<li class="active"><span>系统设置</span></li>
					  </ol>
					</div>
					<!-- /Breadcrumb -->
				</div>
				<!-- /Title -->

                <!-- Row -->
                <div class="row">
                    <div class="col-lg-12 col-sm-12">
                        <div class="panel panel-default card-view">
                            <div class="panel-wrapper collapse in">
                                <div class="panel-body">
                                    <div  class="pills-struct">
                                        <ul role="tablist" class="nav nav-pills" id="myTabs_6">
                                            {notempty name='systemGroup'}
                                            {foreach name='systemGroup' item='value'}
                                            <li {eq name='key' value='0'}class="active"{/eq} role="presentation"><a aria-expanded="true"  data-toggle="tab" role="tab" id="tab_{$value.id}" href="#tab_tab_{$value.id}">{$value.title}</a></li>
                                            {/foreach}
                                            {/notempty}
                                        </ul>
                                        <div class="tab-content" id="myTabContent_6">
                                            {notempty name='systemGroup'}
                                            {foreach name='systemGroup' item='value'}
                                            <div  id="tab_tab_{$value.id}" class="tab-pane fade {eq name='key' value='0'}active in{/eq}" role="tabpanel">
                                                <form class="form-horizontal" method="post" {eq name='key' value='0'}id="system_form"  action="{:url('saveConfig')}"{/eq}>
                                                    {php}$items = system_config_items($value['id']);{/php}
                                                    {notempty name='items'}
                                                    {foreach name='items' item='v' key='k'}
                                                    {switch name='v.type'}
                                                    {case value='text'}
                                                    <div class="form-group">
                                                        <label class="control-label mb-10 col-sm-2" for="{$v.cfg_name}">{$v.cfg_info}:</label>
                                                        <div class="col-sm-8">
                                                            <input type="text" class="form-control" id="{$v.cfg_name}" name="{$v.cfg_name}" placeholder="请输入 {$v.cfg_info}" value="{$v.cfg_value}" form="system_form">
                                                        </div>
                                                        <label class="control-label mb-10 col-sm-2 text-left" style="text-transform:lowercase;">{$v.cfg_name}</label>
                                                    </div>
                                                    {/case}
                                                    {case value='textarea'}
                                                    <div class="form-group">
                                                        <label class="control-label mb-10 col-sm-2" for="{$v.cfg_name}">{$v.cfg_info}:</label>
                                                        <div class="col-sm-8">
                                                            <textarea class="form-control" form="system_form" name="{$v.cfg_name}" id="{$v.cfg_name}" cols="30" rows="5" placeholder="请输入 {$v.cfg_info}">{$v.cfg_value}</textarea>
                                                        </div>
                                                        <label class="control-label mb-10 col-sm-2 text-left" style="text-transform:lowercase;">{$v.cfg_name}</label>
                                                    </div>
                                                    {/case}
                                                    {case value='select'}
                                                    <div class="form-group">
                                                        <label class="control-label mb-10 col-sm-2" for="{$v.cfg_name}">{$v.cfg_info}:</label>
                                                        <div class="col-sm-8">
                                                            <select class="form-control" name="{$v.cfg_name}" id="{$v.cfg_name}" form="system_form">
                                                                {php}$options = explode(',', $v['more']);{/php}
                                                                {foreach name='options' item='o' key='i'}
                                                                <option value="{$i}" {eq name="v.cfg_value" value="$i"}selected="selected"{/eq} >{$o}</option>
                                                                {/foreach}
                                                            </select>
                                                        </div>
                                                        <label class="control-label mb-10 col-sm-2 text-left" style="text-transform:lowercase;">{$v.cfg_name}</label>
                                                    </div>
                                                    {/case}
                                                    {/switch}
                                                    {/foreach}
                                                    {/notempty}

                                                    {eq name='value.id' value='4'}
                                                    <div id="plus_item_box"></div>
                                                    <div class="form-group mb-0">
                                                        <div class="col-sm-12 text-center">
                                                            <button type="button" class="btn btn-warning" data-toggle="modal" data-target="#responsive-modal"><span class="btn-text">添加设置项</span></button>
                                                        </div>
                                                    </div>
                                                    {/eq}
                                                </form>
                                            </div>
                                            {/foreach}
                                            {/notempty}
                                            <div class="form-group mb-0">
                                                <div class="col-sm-offset-2 col-sm-10">
                                                    <button type="submit" class="btn btn-success" form="system_form"><span class="btn-text">保存设置</span></button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /Row -->
			
			</div>
			<!-- Footer -->
			{include file='public/footer' /}
			<!-- /Footer -->
			
		</div>
		<!-- /Main Content -->
		
		</div>
		<!-- /#wrapper -->
		
		<!-- JavaScript -->
		
		<!-- jQuery -->
		<script src="__PUBLIC__/admin/vendors/bower_components/jquery/dist/jquery.min.js"></script>
		
		<!-- Bootstrap Core JavaScript -->
		<script src="__PUBLIC__/admin/vendors/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		
		<!-- Slimscroll JavaScript -->
		<script src="__PUBLIC__/admin/dist/js/jquery.slimscroll.js"></script>
	
		<!-- Fancy Dropdown JS -->
		<script src="__PUBLIC__/admin/dist/js/dropdown-bootstrap-extended.js"></script>
		
		<!-- Owl JavaScript -->
		<script src="__PUBLIC__/admin/vendors/bower_components/owl.carousel/dist/owl.carousel.min.js"></script>
		
		<!-- Switchery JavaScript -->
		<script src="__PUBLIC__/admin/vendors/bower_components/switchery/dist/switchery.min.js"></script>
		
		<!-- Init JavaScript -->
        {include file='public/comn_js' /}
        <script src="__PUBLIC__/admin/vendors/layer/layer.js"></script>
        <script src="__PUBLIC__/admin/dist/js/jquery.form.js"></script>
	</body>
    <!--添加设置项浮动窗口-->
    <div id="responsive-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h5 class="modal-title">添加设置项</h5>
                </div>
                <div class="modal-body">
                    <form method="post" action="{:url('itemAdd')}" id="item_add">
                        <div class="form-group">
                            <label for="cfg_name" class="control-label mb-10">唯一ID:</label>
                            <input type="text" class="form-control" id="cfg_name" name="cfg_name" placeholder="请填写配置项ID，不能重复，不得与thinkphp框架设置项重名" required>
                        </div>
                        <div class="form-group">
                            <label for="cfg_info" class="control-label mb-10">配置项名称:</label>
                            <input type="text" class="form-control" id="cfg_info" name="cfg_info" placeholder="请填写配置项名称" required>
                        </div>
                        <div class="form-group">
                            <label for="cfg_value" class="control-label mb-10">配置项内容:</label>
                            <input type="text" class="form-control" id="cfg_value" name="cfg_value" placeholder="请填写配置项内容">
                        </div>
                        <div class="form-group">
                            <label for="type" class="control-label mb-10">配置项类型:</label>
                            <select name="type" id="type" class="form-control" required>
                                <option value="text">文本</option>
                                <option value="textarea">文本域</option>
                                <option value="select">下拉菜单</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="more" class="control-label mb-10">附加信息:</label>
                            <textarea class="form-control" id="more" name="more" placeholder="如选择下拉菜单，请填写该内容！"></textarea>
                            <span class="text-muted">e.g "0,1"</span>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" onclick="do_item_add();">提交</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
    <script>
        function do_item_add() {
            $('#item_add').submit();
        }
        $('#item_add').submit(function() {
            // submit the form
            $(this).ajaxSubmit({
                success: function (responseText, statusText) {
                    if (responseText.status)
                    {
                        var html = '';
                        switch (responseText.msg.type)
                        {
                            case 'text':
                                html += '<div class="form-group">\n' +
                                        '    <label class="control-label mb-10 col-sm-2" for="'+responseText.msg.cfg_name+'">'+responseText.msg.cfg_info+':</label>\n' +
                                        '    <div class="col-sm-8">\n' +
                                        '        <input type="text" class="form-control" id="'+responseText.msg.cfg_name+'" name="'+responseText.msg.cfg_name+'" placeholder="请输入 '+responseText.msg.cfg_info+'" value="'+responseText.msg.cfg_value+'" form="system_form">\n' +
                                        '    </div>\n' +
                                        '    <label class="control-label mb-10 col-sm-2 text-left">'+responseText.msg.cfg_name+'</label>' +
                                        '</div>';
                                break;
                            case 'textarea':
                                html += '<div class="form-group">\n' +
                                    '    <label class="control-label mb-10 col-sm-2" for="'+responseText.msg.cfg_name+'">'+responseText.msg.cfg_info+':</label>\n' +
                                    '    <div class="col-sm-8">\n' +
                                    '        <textarea class="form-control" form="system_form" name="'+responseText.msg.cfg_name+'" id="'+responseText.msg.cfg_name+'" cols="30" rows="5" placeholder="请输入 '+responseText.msg.cfg_info+'">'+responseText.msg.cfg_value+'</textarea>\n' +
                                    '    </div>\n' +
                                    '    <label class="control-label mb-10 col-sm-2 text-left">'+responseText.msg.cfg_name+'</label>' +
                                    '</div>';
                                break;
                            case 'select':
                                html += '<div class="form-group">\n' +
                                    '    <label class="control-label mb-10 col-sm-2" for="'+responseText.msg.cfg_name+'">'+responseText.msg.cfg_info+':</label>\n' +
                                    '    <div class="col-sm-8">\n' +
                                    '        <select class="form-control" name="'+responseText.msg.cfg_name+'" id="'+responseText.msg.cfg_name+'" form="system_form">';
                                $.each(responseText.msg.more, function (k, v) {
                                   html += '<option value="'+v+'">'+v+'</option>';
                                });
                                html += '    </div>\n' +
                                    '    <label class="control-label mb-10 col-sm-2 text-left">'+responseText.msg.cfg_name+'</label>' +
                                    '</div>';
                                break;
                        }
                        layer.msg('添加成功！', {shade: [0.6, '#000'], time:3000}, function () {
                            $('#plus_item_box').html(html);
                            $('#item_add')[0].reset();
                            $('#responsive-modal').modal('hide');
                        });
                    } else {
                        layer.msg(responseText.msg, {shade: [0.6, '#000'], time:3000}, function () {
                            $('#item_add')[0].reset();
                        });
                    }
                }
            });
            // return false to prevent normal browser submit and page navigation
            return false;
        });
        
        $('#system_form').submit(function () {
            // submit the form
            $(this).ajaxSubmit({
                success: function (responseText, statusText) {
                    if (responseText.status)
                    {
                        layer.msg(responseText.msg, {shade: [0.6, '#000'], time:3000});
                    } else {
                        layer.msg(responseText.msg, {shade: [0.6, '#000'], time:3000}, function () {
                            window.location.reload();
                        });
                    }
                }
            });
            // return false to prevent normal browser submit and page navigation
            return false;
        })
    </script>
</html>